QMainWindow Class 您所在的位置:网站首页 qt mainwindow菜单 QMainWindow Class

QMainWindow Class

2024-07-12 11:33| 来源: 网络整理| 查看: 265

Member Function Documentation [explicit] QMainWindow::QMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a QMainWindow with the given parent and the specified widget flags.

QMainWindow sets the Qt::Window flag itself, and will hence always be created as a top-level widget.

[virtual noexcept] QMainWindow::~QMainWindow()

Destroys the main window.

void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)

Adds the given dockwidget to the specified area.

void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget, Qt::Orientation orientation)

Adds dockwidget into the given area in the direction specified by the orientation.

void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)

Adds the toolbar into the specified area in this main window. The toolbar is placed at the end of the current tool bar block (i.e. line). If the main window already manages toolbar then it will only move the toolbar to area.

See also insertToolBar(), addToolBarBreak(), and insertToolBarBreak().

void QMainWindow::addToolBar(QToolBar *toolbar)

This is an overloaded function.

Equivalent of calling addToolBar(Qt::TopToolBarArea, toolbar)

QToolBar *QMainWindow::addToolBar(const QString &title)

This is an overloaded function.

Creates a QToolBar object, setting its window title to title, and inserts it into the top toolbar area.

See also setWindowTitle().

void QMainWindow::addToolBarBreak(Qt::ToolBarArea area = Qt::TopToolBarArea)

Adds a toolbar break to the given area after all the other objects that are present.

QWidget *QMainWindow::centralWidget() const

Returns the central widget for the main window. This function returns nullptr if the central widget has not been set.

See also setCentralWidget().

[override virtual protected] void QMainWindow::contextMenuEvent(QContextMenuEvent *event)

Reimplements: QWidget::contextMenuEvent(QContextMenuEvent *event).

Qt::DockWidgetArea QMainWindow::corner(Qt::Corner corner) const

Returns the dock widget area that occupies the specified corner.

See also setCorner().

[virtual] QMenu *QMainWindow::createPopupMenu()

Returns a popup menu containing checkable entries for the toolbars and dock widgets present in the main window. If there are no toolbars and dock widgets present, this function returns nullptr.

By default, this function is called by the main window when the user activates a context menu, typically by right-clicking on a toolbar or a dock widget.

If you want to create a custom popup menu, reimplement this function and return a newly-created popup menu. Ownership of the popup menu is transferred to the caller.

See also addDockWidget(), addToolBar(), and menuBar().

Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const

Returns the Qt::DockWidgetArea for dockwidget. If dockwidget has not been added to the main window, this function returns Qt::NoDockWidgetArea.

See also addDockWidget(), splitDockWidget(), and Qt::DockWidgetArea.

[override virtual protected] bool QMainWindow::event(QEvent *event)

Reimplements: QWidget::event(QEvent *event).

[signal] void QMainWindow::iconSizeChanged(const QSize &iconSize)

This signal is emitted when the size of the icons used in the window is changed. The new icon size is passed in iconSize.

You can connect this signal to other components to help maintain a consistent appearance for your application.

See also setIconSize().

void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar)

Inserts the toolbar into the area occupied by the before toolbar so that it appears before it. For example, in normal left-to-right layout operation, this means that toolbar will appear to the left of the toolbar specified by before in a horizontal toolbar area.

See also insertToolBarBreak(), addToolBar(), and addToolBarBreak().

void QMainWindow::insertToolBarBreak(QToolBar *before)

Inserts a toolbar break before the toolbar specified by before.

QMenuBar *QMainWindow::menuBar() const

Returns the menu bar for the main window. This function creates and returns an empty menu bar if the menu bar does not exist.

If you want all windows in a Mac application to share one menu bar, don't use this function to create it, because the menu bar created here will have this QMainWindow as its parent. Instead, you must create a menu bar that does not have a parent, which you can then share among all the Mac windows. Create a parent-less menu bar this way:

QMenuBar *menuBar = new QMenuBar(nullptr);

See also setMenuBar().

QWidget *QMainWindow::menuWidget() const

Returns the menu bar for the main window. This function returns null if a menu bar hasn't been constructed yet.

See also setMenuWidget().

void QMainWindow::removeDockWidget(QDockWidget *dockwidget)

Removes the dockwidget from the main window layout and hides it. Note that the dockwidget is not deleted.

void QMainWindow::removeToolBar(QToolBar *toolbar)

Removes the toolbar from the main window layout and hides it. Note that the toolbar is not deleted.

void QMainWindow::removeToolBarBreak(QToolBar *before)

Removes a toolbar break previously inserted before the toolbar specified by before.

void QMainWindow::resizeDocks(const QList &docks, const QList &sizes, Qt::Orientation orientation)

Resizes the dock widgets in the list docks to the corresponding size in pixels from the list sizes. If orientation is Qt::Horizontal, adjusts the width, otherwise adjusts the height of the dock widgets. The sizes will be adjusted such that the maximum and the minimum sizes are respected and the QMainWindow itself will not be resized. Any additional/missing space is distributed amongst the widgets according to the relative weight of the sizes.

Example:

resizeDocks({blueWidget, yellowWidget}, {20 , 40}, Qt::Horizontal);

If the blue and the yellow widget are nested on the same level they will be resized such that the yellowWidget is twice as big as the blueWidget

If some widgets are grouped in tabs, only one widget per group should be specified. Widgets not in the list might be changed to respect the constraints.

bool QMainWindow::restoreDockWidget(QDockWidget *dockwidget)

Restores the state of dockwidget if it is created after the call to restoreState(). Returns true if the state was restored; otherwise returns false.

See also restoreState() and saveState().

bool QMainWindow::restoreState(const QByteArray &state, int version = 0)

Restores the state of this mainwindow's toolbars and dockwidgets. Also restores the corner settings too. The version number is compared with that stored in state. If they do not match, the mainwindow's state is left unchanged, and this function returns false; otherwise, the state is restored, and this function returns true.

To restore geometry saved using QSettings, you can use code like this:

void MainWindow::readSettings() { QSettings settings("MyCompany", "MyApp"); restoreGeometry(settings.value("myWidget/geometry").toByteArray()); restoreState(settings.value("myWidget/windowState").toByteArray()); }

See also saveState(), QWidget::saveGeometry(), QWidget::restoreGeometry(), and restoreDockWidget().

QByteArray QMainWindow::saveState(int version = 0) const

Saves the current state of this mainwindow's toolbars and dockwidgets. This includes the corner settings which can be set with setCorner(). The version number is stored as part of the data.

The objectName property is used to identify each QToolBar and QDockWidget. You should make sure that this property is unique for each QToolBar and QDockWidget you add to the QMainWindow

To restore the saved state, pass the return value and version number to restoreState().

To save the geometry when the window closes, you can implement a close event like this:

void MyMainWindow::closeEvent(QCloseEvent *event) { QSettings settings("MyCompany", "MyApp"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState()); QMainWindow::closeEvent(event); }

See also restoreState(), QWidget::saveGeometry(), and QWidget::restoreGeometry().

void QMainWindow::setCentralWidget(QWidget *widget)

Sets the given widget to be the main window's central widget.

Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.

See also centralWidget().

void QMainWindow::setCorner(Qt::Corner corner, Qt::DockWidgetArea area)

Sets the given dock widget area to occupy the specified corner.

See also corner().

void QMainWindow::setMenuBar(QMenuBar *menuBar)

Sets the menu bar for the main window to menuBar.

Note: QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.

See also menuBar().

void QMainWindow::setMenuWidget(QWidget *menuBar)

Sets the menu bar for the main window to menuBar.

QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time.

See also menuWidget().

void QMainWindow::setStatusBar(QStatusBar *statusbar)

Sets the status bar for the main window to statusbar.

Setting the status bar to nullptr will remove it from the main window. Note that QMainWindow takes ownership of the statusbar pointer and deletes it at the appropriate time.

See also statusBar().

void QMainWindow::setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition)

Sets the tab position for the given dock widget areas to the specified tabPosition. By default, all dock areas show their tabs at the bottom.

Note: The VerticalTabs dock option overrides the tab positions set by this method.

See also tabPosition() and setTabShape().

void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)

Splits the space covered by the first dock widget into two parts, moves the first dock widget into the first part, and moves the second dock widget into the second part.

The orientation specifies how the space is divided: A Qt::Horizontal split places the second dock widget to the right of the first; a Qt::Vertical split places the second dock widget below the first.

Note: if first is currently in a tabbed docked area, second will be added as a new tab, not as a neighbor of first. This is because a single tab can contain only one dock widget.

Note: The Qt::LayoutDirection influences the order of the dock widgets in the two parts of the divided area. When right-to-left layout direction is enabled, the placing of the dock widgets will be reversed.

See also tabifyDockWidget(), addDockWidget(), and removeDockWidget().

QStatusBar *QMainWindow::statusBar() const

Returns the status bar for the main window. This function creates and returns an empty status bar if the status bar does not exist.

See also setStatusBar().

QTabWidget::TabPosition QMainWindow::tabPosition(Qt::DockWidgetArea area) const

Returns the tab position for area.

Note: The VerticalTabs dock option overrides the tab positions returned by this function.

See also setTabPosition() and tabShape().

[signal] void QMainWindow::tabifiedDockWidgetActivated(QDockWidget *dockWidget)

This signal is emitted when the tabified dock widget is activated by selecting the tab. The activated dock widget is passed in dockWidget.

See also tabifyDockWidget() and tabifiedDockWidgets().

QList QMainWindow::tabifiedDockWidgets(QDockWidget *dockwidget) const

Returns the dock widgets that are tabified together with dockwidget.

See also tabifyDockWidget().

void QMainWindow::tabifyDockWidget(QDockWidget *first, QDockWidget *second)

Moves second dock widget on top of first dock widget, creating a tabbed docked area in the main window.

See also tabifiedDockWidgets().

QWidget *QMainWindow::takeCentralWidget()

Removes the central widget from this main window.

The ownership of the removed widget is passed to the caller.

Qt::ToolBarArea QMainWindow::toolBarArea(const QToolBar *toolbar) const

Returns the Qt::ToolBarArea for toolbar. If toolbar has not been added to the main window, this function returns Qt::NoToolBarArea.

See also addToolBar(), addToolBarBreak(), and Qt::ToolBarArea.

bool QMainWindow::toolBarBreak(QToolBar *toolbar) const

Returns whether there is a toolbar break before the toolbar.

See also addToolBarBreak() and insertToolBarBreak().

[signal] void QMainWindow::toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)

This signal is emitted when the style used for tool buttons in the window is changed. The new style is passed in toolButtonStyle.

You can connect this signal to other components to help maintain a consistent appearance for your application.

See also setToolButtonStyle().



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有